#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    imgInit();
    imgShow();
    ui->verticalSlider->setSliderPosition(50);
    ui->verticalSlider_2->setSliderPosition(50);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::imgInit()
{
    Mat ImgData = imread("test.jpg");
    cvtColor(ImgData,myImg,COLOR_BGR2RGB);
    myQImg = QImage((const unsigned char*)(myImg.data),myImg.cols,myImg.rows,QImage::Format_RGB888);
    imgShow();
}

void MainWindow::imgProc(float con, int bri)
{
    Mat src = myImg;
    Mat dst = Mat::zeros(src.size(),src.type());
    src.convertTo(dst,-1,con,bri);
    myQImg = QImage((const unsigned char*)(dst.data),dst.cols,dst.rows,QImage::Format_RGB888);
    imgShow();
}

void MainWindow::imgShow()
{
    ui->label->setPixmap(QPixmap::fromImage(myQImg.scaled(ui->label->size())));//显示到Qlabel上
}


void MainWindow::on_pushButton_clicked()
{
    imgInit();
    imgShow();
}


void MainWindow::on_verticalSlider_sliderMoved(int position)
{
    imgProc(position/33.3, 0);
}


void MainWindow::on_verticalSlider_valueChanged(int value)
{
    imgProc(value/33.3, 0);
}


void MainWindow::on_verticalSlider_2_sliderMoved(int position)
{
    imgProc(1.0, position);
}


void MainWindow::on_verticalSlider_2_valueChanged(int value)
{
    imgProc(1.0, value);
}

